import { ChatMessageWorking } from "./chatViewData/ChatMessageWorking";
import { ChatBox } from "./chatPanel/ChatBox";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { ChatModule } from "../../../../modules/ChatModule";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { ChatArea } from "./ChatArea";
import { DragItem } from "../common/drag/DragItem";
import { DragItemEvent } from "../common/drag/DragItemEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { SChatMsg } from "../../../../Message/Game/SChatMsg";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { ChatItemData } from "./chatViewData/ChatItemData";
import { ChatCellData } from "./chatViewData/ChatCellData";
import { ChatStyle } from "./chatPanel/ChatStyle";
import { ChatNotes } from "./chatPanel/ChatNotes";
import { ChatType } from "./chatViewData/ChatType";
import { ColorConfig } from "../../resource/ColorConfig";
import { _currentHeight } from "../../../../this/_currentHeight";
import { Team } from "../../../../ChatArea/Team";
type int = number;
//class ChatBody
    
    export  class ChatBody /* flash.display.Sprite */
    {
        constructor(arg1: Array<any>)
        {
            
            this._dataArray = arg1;
            this.mouseEnabled = false;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.initBody();
            this.initScrollPane();
            this.addMessage();
            this.addDragItem();
            return;
        }

        /* internal  */initBody(): void
        {
            var loc2=null;
            var loc3=null;
            this._dataArray = ChatMessageWorking.chatShowAllAreaData;
            this._dicNameChatBox = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=0;
            while (loc1 < this._dataArray.length) 
            {
                loc2 = this._dataArray[loc1];
                loc3 = new ChatBox(30);
                loc3.name = loc2["name"];
                loc3.y = 0;
                this._dicNameChatBox[loc2["name"]] = loc3;
                if (loc1 != 0) 
                {
                    loc3.visible = false;
                }
                else 
                {
                    this._currentChatBox = loc3;
                    loc3.visible = true;
                }
                ++loc1;
            }
            return;
        }

        /* internal  */initScrollPane(): void
        {
            this._scrollPane = new GScrollPane();
            this._scrollPane.verticalScrollBarPos = GScrollPane.SCROLLBARPOSITIONLEFT;
            this._scrollPane.width = ChatModule.ChatWidth;
            this._scrollPane.y = 2;
            this._scrollPane.height = 168;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.ON;
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.mouseEnabled = false;
            (this._scrollPane.content as Object /* flash.display.DisplayObjectContainer */).mouseEnabled = false;
            this.addChild(this._scrollPane);
            this._currentChatBox.parent.mouseEnabled = false;
            this._scrollPane.update();
            return;
        }

        public addMessage(arg1: string=""): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            var loc2=new Object /* flash.text.TextField */();
            loc2.y = 5;
            loc2.x = 5;
            loc2.width = 250;
            loc2.multiline = true;
            loc2.filters = [FilterConst.glowFilter];
            loc2.defaultTextFormat = new GTextFormat(FontUtil.songtiName);
            loc2.htmlText = "<textFormat leading=\'4\'>" + HTMLUtil.addColor(Language.getString(40676), "#ff5b5b") + "</textFormat>";
            loc2.selectable = false;
            loc1.mouseEnabled = false;
            loc1.mouseChildren = false;
            loc1.addChild(loc2);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChild(loc1);
            loc2.height = loc2.textHeight + 10;
            return;
        }

        /* internal  */addDragItem(): void
        {
            this._dragItem = new DragItem(ChatModule.ChatWidth - 20, 5);
            this._dragItem.x = 20;
            this._dragItem.addEventListener(DragItemEvent.DragPositionChange, this.onDragPositionChange);
            this._dragItem.addEventListener(DragItemEvent.StartDrag, this.onStartDrag);
            this.addChild(this._dragItem);
            return;
        }

        /* internal  */onStartDrag(arg1: DragItemEvent): void
        {
            this._lastDragHeight = this._currentHeight;
            return;
        }

        /* internal  */onDragPositionChange(arg1: DragItemEvent): void
        {
            this._currentHeight = this._lastDragHeight - arg1.changeY;
            this._currentHeight = this._currentHeight > this.MaxHeight ? this.MaxHeight : _currentHeight;
            this._currentHeight = this._currentHeight < this.MinHeight ? this.MinHeight : _currentHeight;
            this.resizeHeight(this._currentHeight);
            this.y = -1 * (this._currentHeight + 52);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChatResize));
            return;
        }

        public addChatNotes(arg1: string, arg2: PlayerMiniInfo, arg3: string, arg4: Array<any>=null, arg5: Array<any>=null, arg6: Array<any>=null, arg7: int=-1, arg8: SChatMsg=null): void
        {
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=false;
            if (arg6.indexOf(ChatArea.Force) == -1) 
            {
                arg6.push(ChatArea.Force);
            }
            var loc1=3;
            if (arg2 && !arg2.isVIP) 
            {
                loc1 = 1;
            }
            var loc2=this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var loc3=this._scrollPane.verticalScrollPosition;
            var loc4=false;
            var loc5=0;
            if (loc4 = this._currentChatBox.isMaxLength()) 
            {
                loc5 = this._currentChatBox.getChatNotesAtIndex(0).height;
                loc3 = loc3 - loc5;
            }
            if (arg6.indexOf(arg1) < 0 && !(arg1 == ChatArea.Speaker)) 
            {
                return;
            }
            var loc11=0;
            var loc12=arg6;
            for(loc9 of loc12) 
            {
                if (!(arg1 == loc9 || arg1 == ChatArea.Speaker && loc9 == ChatArea.World)) 
                {
                    continue;
                }
                (loc6 = ObjectPool.getObject(ChatItemData)).type = ChatMessageWorking.getChatTypeByAreaName(arg1);
                loc7 = new Vector.<ChatCellData>();
                if ((loc10 = ChatMessageWorking.chatChannelsData.indexOf(ChatMessageWorking.forceObj) > -1 && (arg1 == ChatArea.Scene || arg1 == ChatArea.Force)) && !(arg7 == -1) && !(arg7 == 0)) 
                {
                    loc7 = loc7.concat(ChatMessageWorking.getForcePlayerCellData(arg2, arg7));
                }
                else if (arg1 != ChatArea.Union) 
                {
                    loc7 = loc7.concat(ChatMessageWorking.getCellDataByPlayerInfo(arg2, ChatStyle.getTitleColor(loc6.type)));
                }
                else 
                {
                    loc7 = loc7.concat(ChatMessageWorking.getCellDataByPlayerInfo(arg2, ChatStyle.getTitleColor(loc6.type), true));
                }
                loc7 = loc7.concat(ChatMessageWorking.getCellDatas(arg3, arg4, arg5, ChatStyle.getTitleColor(loc6.type), 12, loc1));
                loc6.cellVector = loc7;
                (loc8 = ObjectPool.getObject(ChatNotes)).init(loc6, ChatBody.lineWidth, ChatBody.lineHeight);
                (this._dicNameChatBox[loc9] as ChatBox).addChatNotes(loc8);
                if (loc10) 
                {
                    continue;
                }
                (loc6 = ObjectPool.getObject(ChatItemData)).type = ChatMessageWorking.getChatTypeByAreaName(arg1);
                loc7 = new Vector.<ChatCellData>();
                if (arg1 != ChatArea.Union) 
                {
                    loc7 = loc7.concat(ChatMessageWorking.getCellDataByPlayerInfo(arg2, ChatStyle.getTitleColor(loc6.type)));
                }
                else 
                {
                    loc7 = loc7.concat(ChatMessageWorking.getCellDataByPlayerInfo(arg2, ChatStyle.getTitleColor(loc6.type), true));
                }
                loc7 = loc7.concat(ChatMessageWorking.getCellDatas(arg3, arg4, arg5, ChatStyle.getTitleColor(loc6.type), 12, loc1));
                loc6.cellVector = loc7;
                (loc8 = ObjectPool.getObject(ChatNotes)).init(loc6, ChatBody.lineWidth, ChatBody.lineHeight);
                (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(loc8);
            }
            this._scrollPane.validateNow();
            this._scrollPane.update();
            loc3 = loc3 >= 0 ? loc3 : 0;
            if (loc2) 
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else 
            {
                this._scrollPane.verticalScrollPosition = loc3;
            }
            return;
        }

        public addTipNotes(arg1: string, arg2: string, arg3: string="complex", arg4: int=0, arg5: Array<any>=null, arg6: int=16777215): void
        {
            var loc5=null;
            var loc6=null;
            var loc1=this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var loc2=this._scrollPane.verticalScrollPosition;
            var loc3=false;
            var loc4=0;
            if (loc3 = this._currentChatBox.isMaxLength()) 
            {
                loc4 = this._currentChatBox.getChatNotesAtIndex(0).height;
                loc2 = loc2 - loc4;
            }
            (loc5 = ObjectPool.getObject(ChatItemData)).type = arg1;
            loc6 = new Vector.<ChatCellData>();
            if (arg4 == 0) 
            {
                loc6 = loc6.concat(ChatMessageWorking.getCellDataByContent(arg2, ChatStyle.getTitleColor(loc5.type)));
            }
            if (arg4 == 1) 
            {
                loc6 = loc6.concat(ChatMessageWorking.getCellDatasFilterHtml(arg2, ChatStyle.getTitleColor(loc5.type), arg5));
            }
            if (arg4 == 2) 
            {
                loc6 = loc6.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(arg2, arg5, arg6));
            }
            if (!loc6 || loc6.length == 0) 
            {
                return;
            }
            loc5.cellVector = loc6;
            var loc7;
            (loc7 = ObjectPool.getObject(ChatNotes)).init(loc5, ChatBody.lineWidth, ChatBody.lineHeight);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(loc7);
            if (arg3 != ChatArea.Complex) 
            {
                (loc5 = ObjectPool.getObject(ChatItemData)).type = arg1;
                loc6 = new Vector.<ChatCellData>();
                if (arg4 == 0) 
                {
                    loc6 = loc6.concat(ChatMessageWorking.getCellDataByContent(arg2, ChatStyle.getTitleColor(loc5.type)));
                }
                if (arg4 == 1) 
                {
                    loc6 = loc6.concat(ChatMessageWorking.getCellDatasFilterHtml(arg2, ChatStyle.getTitleColor(loc5.type)));
                }
                if (arg4 == 2) 
                {
                    loc6 = loc6.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(arg2, arg5, arg6));
                }
                if (!loc6 || loc6.length == 0) 
                {
                    return;
                }
                loc5.cellVector = loc6;
                (loc7 = ObjectPool.getObject(ChatNotes)).init(loc5, ChatBody.lineWidth, ChatBody.lineHeight);
                (this._dicNameChatBox[arg3] as ChatBox).addChatNotes(loc7);
            }
            this._scrollPane.validateNow();
            this._scrollPane.update();
            loc2 = loc2 >= 0 ? loc2 : 0;
            if (loc1) 
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else 
            {
                this._scrollPane.verticalScrollPosition = loc2;
            }
            return;
        }

        public addRumorMsg(arg1: string, arg2: Array<any>, arg3: string=null): void
        {
            var loc5=null;
            var loc6=null;
            if (!arg3) 
            {
                arg3 = ChatType.Legent;
            }
            var loc1=this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var loc2=this._scrollPane.verticalScrollPosition;
            var loc3=false;
            var loc4=0;
            if (loc3 = this._currentChatBox.isMaxLength()) 
            {
                loc4 = this._currentChatBox.getChatNotesAtIndex(0).height;
                loc2 = loc2 - loc4;
            }
            (loc5 = ObjectPool.getObject(ChatItemData)).type = arg3;
            loc6 = new Vector.<ChatCellData>();
            var loc7=16777215;
            var loc8;
            if (loc8 = ColorConfig.instance.getChatColor("Rumor")) 
            {
                loc7 = loc8.intColor;
            }
            if (!(loc6 = loc6.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(arg1, arg2, loc7))) || loc6.length == 0) 
            {
                return;
            }
            loc5.cellVector = loc6;
            var loc9;
            (loc9 = ObjectPool.getObject(ChatNotes)).init(loc5, ChatBody.lineWidth, ChatBody.lineHeight);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(loc9);
            this._scrollPane.update();
            loc2 = loc2 >= 0 ? loc2 : 0;
            if (loc1) 
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else 
            {
                this._scrollPane.verticalScrollPosition = loc2;
            }
            return;
        }

        public addCopyMsg(arg1: string, arg2: Array<any>, arg3: Boolean=false): Boolean
        {
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=0;
            var loc9=null;
            var loc1=this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var loc2=this._scrollPane.verticalScrollPosition;
            var loc3=false;
            var loc4=0;
            if (loc3 = this._currentChatBox.isMaxLength()) 
            {
                loc4 = this._currentChatBox.getChatNotesAtIndex(0).height;
                loc2 = loc2 - loc4;
            }
            (loc5 = ObjectPool.getObject(ChatItemData)).type = ChatType.Copy;
            loc6 = new Vector.<ChatCellData>();
            loc8 = 16777215;
            if (loc9 = ColorConfig.instance.getChatColor("Rumor")) 
            {
                loc8 = loc9.intColor;
            }
            if (!(loc6 = loc6.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(arg1, arg2, loc8))) || loc6.length == 0) 
            {
                return false;
            }
            loc5.cellVector = loc6;
            (loc7 = ObjectPool.getObject(ChatNotes)).init(loc5, ChatBody.lineWidth, ChatBody.lineHeight);
            var loc10=arg3 ? ChatArea.CrossGrop : Team;
            (this._dicNameChatBox[loc10] as ChatBox).addChatNotes(loc7);
            this._scrollPane.update();
            loc2 = loc2 >= 0 ? loc2 : 0;
            if (loc1) 
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else 
            {
                this._scrollPane.verticalScrollPosition = loc2;
            }
            return true;
        }

        public changToChatItem(arg1: string): void
        {
            if (this._currentChatBox.name == arg1) 
            {
                return;
            }
            this._currentChatBox.visible = false;
            this._currentChatBox = this._dicNameChatBox[arg1] as ChatBox;
            this._currentChatBox.visible = true;
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }

        public resizeHeight(arg1: number): void
        {
            this._scrollPane.setSize(ChatModule.ChatWidth, arg1 - 2);
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.validateNow();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }

        public updateTabBarData(): void
        {
            return;
        }

        public get currentHeight(): number
        {
            return this._currentHeight;
        }

        /* internal */ /* const */MaxHeight: number=170;

        /* internal */ /* const */MinHeight: number=60;

        public static /* const */lineHeight: number=21;

        public static /* const */lineWidth: number=250;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_dataArray: Array<any>;

        /* internal */ /* var */_currentChatBox: ChatBox;

        /* internal */ /* var */_dicNameChatBox: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_dragItem: DragItem;

        /* internal */ /* var */_currentHeight: number=170;

        /* internal */ /* var */_lastDragHeight: number;
    }
